package acwing._1_1AlgorithmBasic._3SearchGraph;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._3SearchGraph
 * @File : Q0843.java
 * @Author : WangRuoyu
 * @Date : 2023/4/1 11:01
 */

import java.io.*;

public class Q0843 {
    static int n;
    static int[][] vis;
    static boolean[][] se;
    static int[][] dis = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
    static int res = 0;

    static void visited(int i, int j, int c) {
        vis[i][j] += c;
        for (int[] di : dis) {
            int p = i + di[0];
            int q = j + di[1];
            while (p >= 0 && p < n && q >= 0 && q < n) {
                vis[p][q] += c;
                p += di[0];
                q += di[1];
            }
        }
    }

    static void dfs(int x, BufferedWriter wr) throws IOException {
        if (x == n) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (se[i][j]) wr.write("Q");
                    else wr.write(".");
                }
                wr.write("\n");
            }
            wr.write("\n");
            res++; // 计算答案个数
            return;
        }
        for (int i = 0; i < n; ++i) {
            if (vis[x][i] == 0) {
                se[x][i] = true;
                visited(x, i, 1);
                dfs(x + 1, wr);
                se[x][i] = false;
                visited(x, i, -1);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        vis = new int[n][n];
        se = new boolean[n][n];
        dfs(0, wr);
//        System.out.println(res);
        wr.flush();
    }
}
